<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>商品管理</el-breadcrumb-item>
            <el-breadcrumb-item>商品列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-row type="flex">
                <el-col>
                    <el-input placeholder="请输入内容" class="input-with-select">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                    <el-button @click="addGoods">添加商品</el-button>
                </el-col>
            </el-row>
        </el-card>
        <el-table :data="goodsTableData" border style="width: 100%">
            <el-table-column type="index" label="#"></el-table-column>
            <el-table-column prop="goods_name" label="商品名称"></el-table-column>
            <el-table-column prop="goods_price" label="商品价格(元)" width="150"></el-table-column>
            <el-table-column prop="goods_weight" label="商品重量" width="150"></el-table-column>
            <el-table-column label="创建时间" width="170">
                <template slot-scope="{row}">
                    <div>
                        {{ row.add_time | filterTime }}
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="150">
                <template>
                    <el-button type="primary" icon="el-icon-edit" size="mini"></el-button>
                    <el-button type="danger" icon="el-icon-delete" size="mini"></el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum" :page-sizes="[10, 20, 30, 40]" :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
        <dialog-com @addBtn="getTable" :dialogInfo="dialogInfo"></dialog-com>
    </div>
</template>

<script>
import dialogCom from './components/dialogCom.vue'
import { getGoodsApi } from '@/api/goods';
export default {
    components: { dialogCom },
    data() {
        return {
            queryInfo: {
                query: "",
                pagenum: 1,
                pagesize: 10
            },
            goodsTableData: [],
            total: 0,
            dialogInfo: {
                title: "添加商品",
                isShow: false,
                options: 'add'
            }
        }
    },
    created() {
        this.getTable()
    },
    methods: {
        async getTable() {
            let res = await getGoodsApi(this.queryInfo)
            console.log(res);
            this.goodsTableData = res.goods
            this.total = res.total

        },
        // 添加商品
        addGoods() {
            this.dialogInfo = {
                title: "添加商品",
                isShow: true,
                options: 'add'
            }
        },
        handleSizeChange(val) {
            this.queryInfo.pagesize=val
            this.getTable()
        },
        handleCurrentChange(val) {
            this.queryInfo.pagenum=val
            this.getTable()
        }
    }
}
</script>

<style lang="scss" scoped>
.input-with-select {
    width: 350px;
}
</style>